package com.tfswx.jcyw.sqlmodel.api.bean.table;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 张述江
 * @date 2023/9/15
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SetOperationList extends Select {
    private List<ParenthesedSelect> selects = new ArrayList<>();
    private List<SetOperation> operations = new ArrayList<>();
//    private List<MyOrderByElement> orderByElements;

    public SetOperationList(Select select) {
//        select.setAlias(null);
        selects.add(new ParenthesedSelect(select));
    }

    public SetOperationList() {
    }

    @Override
    public StringBuilder appendSelectBodyTo(StringBuilder builder) {
        for (int i = 0; i < selects.size(); i++) {
            if (i != 0) {
                builder.append(" ").append(operations.get(i - 1).toString()).append(" ");
            }
            builder.append(selects.get(i).toString());
        }
//        if (orderByElements != null) {
//            builder.append(MyPlainSelect.orderByToString(orderByElements));
//        }
        return builder;
    }

    public void addSelect(SetOperation setOperation, Select select) {
        operations.add(setOperation);
//        select.setAlias(null);
        selects.add(new ParenthesedSelect(select));
    }

    @Override
    public String toString() {
        return super.toString();
    }
}
